package com.ict.txmsv2.controller;

import com.ict.txmsv2.model.CheckUser;
import com.ict.txmsv2.model.MethodDescrition;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.services.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author linzzz
 * @desc ...
 * @date 2020-12-16
 */
@RestController
public class ResigterController {

    @Autowired
    CheckService checkService;

    @PostMapping("/regs")
    @MethodDescrition("注册")
    public RespBean Register(@RequestBody CheckUser checkUser){
        checkUser.setEnabled(1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date());
        checkUser.setSubtime(date);
        checkUser.setCheckuserid(1);
        checkUser.setCheckstate(0);
        checkUser.setAvatar("https://s1.ax1x.com/2020/10/28/B8Cgqx.png");
        checkUser.setPassword(new BCryptPasswordEncoder().encode(checkUser.getPassword()));
        if (checkService.register(checkUser) == 1) {
            return RespBean.ok("恭喜你成功提交注册申请，我们将会在1个工作日内通过邮箱给你答复");
        }
        return RespBean.error("出错了");
    }
}
